<template>
  <div class="eventLevel">
    <CommonBtn label-name="月份设定管理" v-if="!button || (button.event!='add()' && button.event!='edit()'&& button.event!='detail()')" :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+(item.type=='search'?item.proxy:item.value)}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()'&& button.event!='detail()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions" @dbClick="openItem"></CommonList>
    <CommonEdit v-if="button && (button.event=='add()' || button.event=='edit()' || button.event=='detail()')"
                :outBtn="button" :props="add"
                :original-data="row" :add-url="$api.API_ADDMDMMONTH" :edit-url="$api.API_UPDMDMMONTH"
                @editBack="editBack"></CommonEdit>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_EXPORTMDMMONTH" :conditions="conditions"></CommonExport>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList";
    import CommonBtn from "../../common/CommonBtn";
    import CommonEdit from "../../common/CommonEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    export default {
        name:'dataMonth',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.ADD,
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'year',
                        label:'年份',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'year',
                                label:'年份',
                                search:true,
                                type:'text',
                            },
                            {
                                prop:'createTime',
                                label:'创建时间'
                            },
                            {
                                prop:'modifyTime',
                                label:'最后修改时间'
                            },
                            {
                                prop:'isValid',
                                label:'是否激活'
                            },
                        ],
                        searchUrl:this.$api.API_SELECTMDMYEAR,
                        searchLabel:'年份设定',
                        searchProxy:'year',
                        searchValue:'pkid',
                        queryProp:'fkMDMYear'
                    },
                    {
                        prop:'cycle',
                        label:'Cycle',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'year',
                                label:'年份',
                                search:true,
                                type:'search',
                                columns:[
                                    {
                                        prop:'year',
                                        label:'年份',
                                        search:true,
                                        type:'text',
                                    },
                                    {
                                        prop:'createTime',
                                        label:'创建时间'
                                    },
                                    {
                                        prop:'modifyTime',
                                        label:'最后修改时间'
                                    },
                                    {
                                        prop:'isValid',
                                        label:'是否激活'
                                    },
                                ],
                                searchUrl:this.$api.API_SELECTMDMYEAR,
                                searchLabel:'年份设定',
                                searchProxy:'year',
                                searchValue:'pkid',
                                queryProp:'fkMDMYear'
                            },
                            {
                                prop:'cycle',
                                label:'Cycle',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'beginTime',
                                label:'开始时间',
                            },
                            {
                                prop:'beginBTime',
                                label:'开始时间起始',
                                search:true,
                                searchOnly:true,
                                type:'date'
                            },
                            {
                                prop:'beginETime',
                                label:'开始时间结束',
                                search:true,
                                searchOnly:true,
                                type:'date'
                            },
                            {
                                prop:'endTime',
                                label:'结束时间',
                            },
                            {
                                prop:'endBTime',
                                label:'结束时间起始',
                                search:true,
                                searchOnly:true,
                                type:'date'
                            },
                            {
                                prop:'endETime',
                                label:'结束时间结束',
                                search:true,
                                searchOnly:true,
                                type:'date'
                            },
                            {
                                prop:'createUserName',
                                label:'创建者'
                            },
                            {
                                prop:'modifyUserName',
                                label:'最后修改者'
                            },
                            {
                                prop:'createTime',
                                label:'创建时间'
                            },
                            {
                                prop:'modifyTime',
                                label:'最后修改时间'
                            }
                        ],
                        searchUrl:this.$api.API_SELECTMDMCYCLE,
                        searchLabel:'Cycle设定',
                        searchProxy:'cycle',
                        searchValue:'pkid',
                        queryProp:'fkMDMCycle'
                    },
                    {
                        prop:'apMonth',
                        label:'月份',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'isActive',
                        label:'激活状态',
                        search:true,
                        type:'checkbox'
                    },
                    {
                        prop:'beginTime',
                        label:'开始时间',
                    },
                    {
                        prop:'beginBTime',
                        label:'开始时间起始',
                        search:true,
                        searchOnly:true,
                        type:'date'
                    },
                    {
                        prop:'beginETime',
                        label:'开始时间结束',
                        search:true,
                        searchOnly:true,
                        type:'date'
                    },
                    {
                        prop:'endTime',
                        label:'结束时间',
                    },
                    {
                        prop:'endBTime',
                        label:'结束时间起始',
                        search:true,
                        searchOnly:true,
                        type:'date'
                    },
                    {
                        prop:'endETime',
                        label:'结束时间结束',
                        search:true,
                        searchOnly:true,
                        type:'date'
                    },
                    {
                        prop:'createUserName',
                        label:'创建者'
                    },
                    {
                        prop:'modifyUserName',
                        label:'最后修改者'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                listUrl: this.$api.API_SELECTMDMMONTH,
                button:null,
                add:{
                    label:'月份设定',
                    addItems:[
                        {name:'年份',prop:'fkMDMYear',type:'select',required:true,optionsUrl:this.$api.API_SELECTMDMYEAR,optionProxy:'year',optionValue:'pkid'},
                        {name:'Cycle',prop:'fkMDMCycle',type:'select',required:true,optionsUrl:this.$api.API_SELECTMDMCYCLE,optionProxy:'cycle',optionValue:'pkid'},
                        {name:'月份',prop:'apMonth',type:'text'},
                        {name:'激活状态',prop:'isActive',type:'checkbox',trueLabel:1,falseLabel:0},
                        {name:'开始时间',prop:'beginTime',type:'date'},
                        {name:'结束时间',prop:'endTime',type:'date'},
                        {name:'备注',prop:'memo',type:'textarea'}
                    ],
                },
                conditions:[],
                row:{}
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()') {
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
                this.$delete (this.row,'createTime')
                this.$delete (this.row,'modifyTime')
            },
            conditionChange(conditions) {
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            },
            openItem(item) {
                this.button = this.$config.BTNS.DETAIL
            },
        },
        components:{CommonExport,SearchPopUp, CommonList,CommonBtn,CommonEdit,},
    }
</script>
